﻿<UserControl x:Class="QplusClassLibrary.Views.ContactsList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    xmlns:views="clr-namespace:QplusClassLibrary.Views"
    xmlns:vm="clr-namespace:QplusClassLibrary.ViewModel"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    MaxWidth="200">
    <!--
    xmlns:lightToolkit="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7"
    xmlns:command="clr-namespace:TwitterPlatform.Commands"-->

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.Resources>          
            <DataTemplate  x:Key="ItemTemplate">
                <!-- 定义显示每一项数据的数据模板-->
                <views:ContactsItem>                  
                </views:ContactsItem>
            </DataTemplate>
            <!-- 定义Xaml对应的ViewModel-->
            <vm:ContactsListViewModel x:Key="ContractsListViewModel"></vm:ContactsListViewModel>
        </Grid.Resources>
        <!--在这里为了简单起见，我直接把ListBox的DataContext设置为ViewModel，
        ViewModel实现了IEnumerable)，这样list的ItemsSource直接binding就可以-->
        <ListBox DataContext="{StaticResource ContractsListViewModel}"
            ItemsSource="{Binding}" 
            ItemTemplate="{StaticResource ItemTemplate}"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel></toolkit:WrapPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <!--对LstBox的loaded事件附件绑定命令，同样，List的数据加载也可以在这个命令excute里进行，然后将ItemsSource绑定到一个集合-->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Loaded"  >
                    <!--<lightToolkit:EventToCommand Command="{Binding LoadedCommand, Mode=OneWay}"></lightToolkit:EventToCommand>-->
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ListBox>
    </Grid>
</UserControl>
